package demo03;

import java.util.Random;

//迷宫类
class Maze {
  private CellType[][] grid;
  private final int SIZE = 8;

  public Maze() {
      grid = new CellType[SIZE][SIZE];
      Random rand = new Random();
      
      for (int i = 0; i < SIZE; i++) {
          for (int j = 0; j < SIZE; j++) {
              if ((i == 0 && j == 0) || (i == SIZE-1 && j == SIZE-1)) {
                  grid[i][j] = CellType.EMPTY;
              } else {
                  int r = rand.nextInt(100);
                  if (r < 20)        grid[i][j] = CellType.F;
                  else if (r < 50)   grid[i][j] = CellType.MONSTER;
                  else if (r < 60)   grid[i][j] = CellType.POTION;
                  else if (r < 70)   grid[i][j] = CellType.IRON_SWORD;
                  else if (r < 80)   grid[i][j] = CellType.SPELL_BOOK;
                  else               grid[i][j] = CellType.ARMOR;
              }
          }
      }
  }

  public CellType getCell(int x, int y) {
      return grid[x][y];
  }

  public void setCell(int x, int y, CellType type) {
      grid[x][y] = type;
  }

  public int getSize() {
      return SIZE;
  }
}